<?php

namespace App\Http\Requests\Business;

use Illuminate\Foundation\Http\FormRequest;

class InvoiceDetailsRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'year' => 'numeric',
            'month' => 'numeric',
            'sales_order_no' => 'required|numeric',
            'sales_order_line_no' => 'required|numeric',
            'material' => 'required|max:100|exists:material,material',
            'quantity' => 'required|integer',
            'total_price_tax_discount' => 'required|numeric',
            'total_price_tax' => 'required|numeric',
            'total_price_no_tax' => 'required|numeric',
            'tax' => 'required|numeric',
            'discount' => 'required|numeric',
            'surcharge' => 'required|numeric',
            'sales_order_type_code' => 'exists:sales_order_type,code',
            'project_type_code' => 'exists:project_type,code',
            'sales_organization_code' => 'exists:sales_organization,code',
            'sales_region_code' => 'exists:sales_region,code',
            'sales_office_code' => 'exists:sales_office,code',
            'distribution_channel_code' => 'exists:distribution_channel,code',
            'payer_id' => 'required|exists:payer,payer_id',
            'salesman_id' => 'required|exists:salesman,job_number',

        ];
        switch (request()->method) {
            case 'POST':
                break;
            case 'PUT':
                break;
            default:
                break;
        }

        return $rules;
    }

    public function messages()
    {
        return [
            'year.numeric' => '请选择年份！',
            'month.numeric' => '请选择月份！',
            'sales_order_no.required' => '请输入销售订单号！',
            'sales_order_no.numeric' => '销售订单号为数字格式！',
            'sales_order_line_no.required' => '请输入销售订单行号！',
            'sales_order_line_no.numeric' => '销售订单行号为数字格式！',
            'material.required' => '请输入物料编码！',
            'material.max' => '物料编码长度最大为100个字符！',
            'material.exists' => '物料编码不存在！',
            'quantity.required' => '请输入开票数量！',
            'quantity.integer' => '开票数量必须为整数！',
            'total_price_tax_discount.required' => '请输入开票总价(含税)(折扣前)！',
            'total_price_tax_discount.numeric' => '开票总价(含税)(折扣前)为数字格式！',
            'total_price_tax.required' => '请输入开票总价(含税)！',
            'total_price_tax.numeric' => '开票总价(含税)为数字格式！',
            'total_price_no_tax.required' => '请输入开票总价(不含税)！',
            'total_price_no_tax.numeric' => '开票总价(不含税)为数字格式！',
            'tax.required' => '请输入税额！',
            'tax.numeric' => '税额为数字格式！',
            'discount.required' => '请输入折扣金额！',
            'discount.numeric' => '折扣金额为数字格式！',
            'surcharge.required' => '请输入附加费！',
            'surcharge.numeric' => '附加费为数字格式！',
            'sales_order_type_code.exists' => '请选择销售订单类型',
            'project_type_code.exists' => '请选择项目类型',
            'sales_organization_code.exists' => '请选择销售组织',
            'sales_region_code.exists' => '请选择销售大区',
            'sales_office_code.exists' => '请选择销售办事处',
            'distribution_channel_code.exists' => '请选择分销渠道',
            'payer_id.required' => '请输入付款方id！',
            'payer_id.exists' => '付款方id不存在！',
            'salesman_id.required' => '请输入业务员工号！',
            'salesman_id.exists' => '业务员工号不存在！',
        ];
    }
}
